﻿/*
 * 文件名称：
 * 程序员：wangyun
 * 创建时间：2008/06/16
 * 
 * 功能说明：功能模块模板导出页面
 * 
 * 修改人员：
 * 
 * 修改日期：
 * 
 * 修改记录：
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class Whir_System_Module_CommonModel_ModelTemplateExport : System.Web.UI.Page
{
    protected int ModelTemplateID = 0;
    protected string ModelTemplateName = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        RoleHelper.IsLogin();    //登录判断

        ModelTemplateID = NetRequest.GetQueryInt("ModelTemplateID");
        ModelTemplateName = Server.UrlDecode(NetRequest.GetQueryString("ModelTemplateName"));

        if (!IsPostBack)
        {
            BindData();
        }
    }

    private void BindData()
    {
        lbTemplateName.Text = ModelTemplateName;

        //绑定已存在的模板
        string templateName = "";
        foreach (DataRow row in FileSystemObject.GetDirectoryInfos(HttpContext.Current.Server.MapPath("~/Temp/ModelTemplates/"), FsoMethod.File).Rows)
        {
            templateName = row["name"].ToString();
            this.lbIsExistsList.Items.Add(new ListItem(templateName, templateName));
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Whir.BLL.Whir_ModelTemplate bll = new Whir.BLL.Whir_ModelTemplate();
        Whir.Model.Whir_ModelTemplate model = bll.GetModel(ModelTemplateID);

        string fileName = model.TemplateName;
        int selectModelID = 0;

        try
        {
            selectModelID = Convert.ToInt32(model.TemplateFields.Split('|')[0].ToString());
            ModelTemplateHelper.Export(selectModelID, fileName);
            JsHelper.Alert(Page, string.Format("[{0}]功能模块模板导出成功", fileName));
        }
        catch
        {
            JsHelper.Alert(Page, string.Format("[{0}]功能模块模板导出失败", fileName));
        }
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("ModelTemplateManage.aspx");        
    }
}
